#include <bits/stdc++.h>
#define rep(i, l, r) for (int i = l; i <= r; ++i)
using namespace std;
const int N = 55;
char a[N][N];
int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
int dy[] = {0, 0, 1, -1, 1, -1, -1, 1};
int n, m;
char tar;
map<pair<int, int>, int> mp;
int dir;
bool out(int x, int y) { return x < 1 || x > n || y < 1 || y > n; }
void getfar(int x, int y, int i, int &d, int &xx, int &yy) {
  int dep = 0;
  while (!out(x + dx[i], y + dy[i])) {
    x += dx[i];
    y += dy[i];
    ++dep;
    if (tar == a[x][y] && dep > d) {
      d = dep;
      xx = x, yy = y;
    } else if (a[x][y] != 'b' && a[x][y] != 'w')
      return;
  }
}
void trans(char &tar) {
  if (tar == 'w')
    tar = 'b';
  else
    tar = 'w';
}
int cir;
void op() {
  int x, y;
  cin >> x >> y;
  ++x, ++y;
  a[x][y] = tar;
  trans(tar);
  ++cir;
  rep(i, 0, 7) {
    int dis = 0, xx = x, yy = y;
    getfar(x, y, i, dis, xx, yy);
    if (dis >= 2) {
      int nx = x, ny = y;
      while (x != xx || y != yy) {
        x += dx[i];
        y += dy[i];
        if (x == xx && y == yy) break;
        if (!(mp.count({x, y}) && mp[{x, y}] == cir - 1)) {
          mp[{x, y}] = cir;
          trans(a[x][y]);
        }
      }
      x = nx;
      y = ny;
    }
  }
}
void solve() {
  memset(a, 0, sizeof a);
  mp.clear();
  tar = 'w';
  cir = 0;
  cin >> n >> m;
  rep(i, 1, n) cin >> a[i] + 1;
  while (m--) op();
  rep(i, 1, n) cout << a[i] + 1 << '\n';
//   cout << "END\n";
}
int main() {
  int T;
  cin >> T;
  while (T--) solve();
  return 0;
}
/*
2
6 4
------
---b--
-wwwb-
-bbw--
-ww---
-ww---
1 2
0 2
2 0
2 5
6 4
------
--b---
--wbb-
--www-
--b-b-
--w---
1 4
1 1
5 4
0 2
*/

/*
--b---
--bb--
wbwbwb
-www--
-wb---
-ww---
END
--b---
-bw-w-
--wbw-
--bwb-
--w-w-
--w-w-
END
*/
